<style lang="less">

</style>
<template>
    <div>
        <Drawer :closable="false" placement="right" v-model="drawerVisible" width="50%" :title="drawerTitle">
            <Row>
                <Col>
                <Card :shadow="false">
                    <Row>
                        <Form ref="form" :model="form" :label-width="90" style="position:relative" :rules="formValidate">
                            <FormItem label="分类名称" prop="conditionName">
                                <Input v-model="form.examTypeName" style="width:600px"/>
                            </FormItem>
                            <FormItem label="分类code" prop="examTypeCode">
                                <Input v-model="form.examTypeCode" style="width:600px"/>
                            </FormItem>
                            <FormItem label="排序" prop="sortOrder">
                                <Input v-model="form.sortOrder" style="width:600px"/>
                            </FormItem>
                            <Form-item class="br">
                                <Button type="primary" :loading="submitLoading" @click="handelSubmit" style="width:80px">提交</Button>
                                <Button @click="handelCancel">取消</Button>
                            </Form-item>
                            <Spin size="large" fix v-if="loading"></Spin>
                        </Form>
                    </Row>
                </Card>
                </Col>
            </Row>
        </Drawer>
    </div>
</template>
<script>
    import {saveOrEdit, selectCertificateList, selectEnumItem} from "@/api/bus";
    import uploadInput from "@/views/my-components/flyme/upload-input";
    // 表情包配置 自定义表情可在该js文件中统一修改
    import {sina} from "@/libs/emoji";
    export default {
        name: "examtype-drawer",
        components: {
            uploadInput
        },
        data() {
            return {
                isCertificate: 1,
                loading: false, // 表单加载状态
                drawerTitle: "证书报考条件项编辑",
                drawerVisible: false,
                isEdit: false,
                certificateList: [],
                worksList: [],
                educationList: [],
                form: {
                    id: '',
                    conditionName: '',
                    conditionValue: '',
                    conditionType: 1,
                },
                formValidate: {
                    // 表单验证规则
                    conditionName: [{required: true, message: "条件名称不能为空", trigger: "blur"}],
                    conditionValue: [{required: true, message: "条件值不能为空", trigger: "blur"}],
                },
                submitLoading: false, // 添加或编辑提交状态
            };
        },
        methods: {
            init(){
                this.getCertificates()
            },
            showDrawer(params) {
                this.getEnumItem()
                if(params){
                    this.isEdit = true
                    this.form.id = params.id
                    this.form.conditionName = params.conditionName
                    this.form.conditionValue = params.conditionValue
                    this.form.conditionType = params.conditionType
                    this.isCertificate = params.conditionType
                }else{
                    this.isEdit = true
                    this.getForm()
                }
                this.drawerVisible = true;
            },
            //获取条件类型
            getEnumItem() {
                selectEnumItem().then(res => {
                    console.info(res.data)
                    if (res.status === true) {
                        this.educationList = res.data.educationList
                        this.worksList = res.data.worksList
                    }
                });
            },
            getForm(){
                this.form.id = ''
                this.form.conditionName = ''
                this.form.conditionValue = 0
                this.form.conditionType = 1
                this.isCertificate = 1
            },
            getCertificates(){
                selectCertificateList().then(res => {
                    if (res.status === true) {
                        this.certificateList = res.data
                    }
                });
            },
            selectJump(){
                if(this.form.conditionType == 4){//选择证书类型
                    this.isCertificate = 4
                    this.form.conditionValue = this.certificateList[0].value
                }else if(this.form.conditionType == 2){
                    this.isCertificate = 2
                    this.form.conditionValue = 0
                }else{
                    this.isCertificate = 1
                    this.form.conditionValue = 1
                }
            },
            handelSubmit() {
                this.$refs.form.validate(valid => {
                    if (valid) {
                        this.submitLoading = true;
                        console.info('form：' + JSON.stringify(this.form))
                        // 编辑
                        saveOrEdit(this.form).then(res => {
                            this.submitLoading = false;
                            if (res.status === true) {
                                this.$Message.success("操作成功");
                                this.$parent.getDataList();
                                this.drawerVisible = false;
                            }
                        });
                    }
                });
            },
            handelCancel() {
                this.drawerVisible = false;
            }
        },
        mounted() {
            this.init();
        },
        watch: {

        }
    };
</script>